﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;

namespace DevExpressDemos.Controls.GridControl
{
    public partial class 无记录显示自定义字符 : Frm_GridControlDemo
    {
        public 无记录显示自定义字符()
        {
            InitializeComponent();
            gridView1.CustomDrawEmptyForeground += view_CustomDrawEmptyForeground;
        }
        private void view_CustomDrawEmptyForeground(object sender, CustomDrawEventArgs e)
        {
            ColumnView columnView = sender as ColumnView;
            BindingSource bindingSource = this.gridView1.DataSource as BindingSource;
            if (bindingSource == null || bindingSource.Count == 0)
            {
                string str = "没有数据!";
                Font f = new Font("宋体", 10, FontStyle.Bold);
                Rectangle r = new Rectangle(e.Bounds.Top + 5, e.Bounds.Left + 100, e.Bounds.Right - 5, e.Bounds.Height - 5);
                e.Graphics.DrawString(str, f, Brushes.Black, r);
            }
        }

        private void Btn_Clear_Click(object sender, EventArgs e)
        {
            gridControl1.DataSource = null;
        }
    }
}